package com.foo.common.base.dao;

import java.io.Serializable;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class FooGenericDaoImpl implements FooGenericDao {

	@Autowired
	private SessionFactory sessionFactory;

	@Override
	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}

	/**
	 * Get the current Hibernate session
	 */
	@Override
	public Session getSession() {
		return sessionFactory.getCurrentSession();
	}

	@Override
	public Object get(Class<?> clazz, Serializable id) {
		return getSession().get(clazz, id);
	}

	@Override
	public Serializable save(Object object) {
		return getSession().save(object);
	}

	@Override
	public void delete(Object object) {
		getSession().delete(object);
	}

	@Override
	public Serializable save(String entityName, Object object) {
		return getSession().save(entityName, object);
	}

	@Override
	public void saveOrUpdate(Object object) {
		getSession().saveOrUpdate(object);
	}

	@Override
	public void update(Object object) {
		getSession().update(object);
	}

}
